bitkeeper revision 1.198 (3eb067ccnZGiSrE___bi3AnWpeUuIw)
authorach61@labyrinth.cl.cam.ac.uk <ach61@labyrinth.cl.cam.ac.uk>
Thu, 1 May 2003 00:18:20 +0000 (00:18 +0000)
committerach61@labyrinth.cl.cam.ac.uk <ach61@labyrinth.cl.cam.ac.uk>
Thu, 1 May 2003 00:18:20 +0000 (00:18 +0000)
allow creation of vbd directly from disk partition
error checking to ensure that /proc/partitions is from a xeno machine

tools/vdmanager/src/uk/ac/cam/cl/xeno/vdmanager/Parser.java
tools/vdmanager/src/uk/ac/cam/cl/xeno/vdmanager/PartitionManager.java
tools/vdmanager/src/uk/ac/cam/cl/xeno/vdmanager/VirtualDisk.java
tools/vdmanager/src/uk/ac/cam/cl/xeno/vdmanager/VirtualDiskManager.java

index 0ce703a2cbaf141925a49d6058f44c423224c822..dee6454fc8d919e2d1410bdf6a5e09344c5566e6 100755 (executable)
@@ -252,6 +252,45 @@ Parser
       return;
     }
 
+    if (commands[1].startsWith("sd") ||
+       commands[1].startsWith("hd"))
+    {
+      /*
+       * this is a gross hack to allow you to create a virtual block
+       * device that maps directly to a physical partition
+       */
+
+      /* find the appropriate partition */
+      Partition partition = pm.get_partition(commands[1]);
+      if (partition == null)
+      {
+       System.out.println ("vbdcreate error: couldn't find partition \"" +
+                           commands[1] + "\"");
+       return;
+      }
+
+      /* create a virtual disk */
+      vd = new VirtualDisk("vbd:" + commands[1]);
+      vd.add_new_partition(partition, partition.nr_sects);
+
+
+      /* display result */
+      System.out.print("domain:" + commands[2] + " ");
+      if (commands.length == 4)
+      {
+       System.out.print ("rw ");
+      }
+      else
+      {
+       System.out.print(commands[4] + " ");
+      }
+      System.out.print("segment:" + commands[3] + " ");
+      System.out.print(vd.dump_xen());
+      System.out.println("");
+
+      return;
+    } 
+
     if (commands.length == 4)
     {
       vbd =
@@ -269,6 +308,7 @@ Parser
                                      commands[4]);
     }
 
+    /* display commandline to user */
     {
       vd = vdm.get_virtual_disk_key(commands[1]);
       System.out.println ("\n" + vd.dump_xen(vbd) + "\n");
@@ -280,7 +320,7 @@ Parser
   {
     if (commands.length < 3)
     {
-      System.out.println ("vbdcreate <domain number> <vbd number>");
+      System.out.println ("vbddelete <domain number> <vbd number>");
       return;
     }
 
index 72f5982aff3da05c063753f7a0f1d62e45aa331c..b0177f504d48062e88b14820c97400cbd14d9fa2 100755 (executable)
@@ -7,6 +7,7 @@ package uk.ac.cam.cl.xeno.vdmanager;
 
 import java.io.*;
 import java.util.Vector;
+import java.util.Enumeration;
 
 public class
 PartitionManager
@@ -14,6 +15,9 @@ PartitionManager
   Vector partition_map;
   Vector xeno_partition_list;
 
+  static String proc_template =
+    "major minor  #blocks  start_sect   nr_sects name";
+
   /*
    * Initialize partition manager with source file.
    * Normally we read from /proc/partitions, but we can
@@ -32,6 +36,14 @@ PartitionManager
       in = new BufferedReader(new FileReader(filename));
 
       str = in.readLine();                                  /* skip headings */
+      if (str.length() < proc_template.length() ||
+         !str.substring(0, proc_template.length()).equals(proc_template))
+      {
+       System.err.println ("Error: Incorrect /proc/partitions.");
+       System.err.println ("       Is this Xeno?");
+       System.exit (1);
+      }
+
       str = in.readLine();                                /* skip blank line */
 
       str = in.readLine();
@@ -58,6 +70,21 @@ PartitionManager
     }
   }
 
+  Partition
+  get_partition (String name)
+  {
+    Partition partition = null;
+    for (Enumeration e = partition_map.elements() ; e.hasMoreElements() ;) 
+    {
+      partition = (Partition) e.nextElement();
+      if (partition.name.equals(name))
+      {
+       return partition;
+      }
+    }
+    return null;
+  }
+
   Partition
   get_partition (int index)
   {
index 0e529edfa268e18eb5a000746384a224610d6f43..2a4947017089c83bd27686f57b6c3bf023511bac 100755 (executable)
@@ -133,6 +133,22 @@ VirtualDisk
     return sb.toString();
   }
 
+  String
+  dump_xen ()
+  {
+    StringBuffer sb = new StringBuffer();
+
+    sb.append("extents:" + extents.size() + " ");
+    for (int loop = 0; loop < extents.size(); loop++)
+    {
+      Extent e = (Extent) extents.get(loop);
+      sb.append("(disk:" + e.disk + " " +
+               "offset:" + e.offset + " " +
+               "size:" + e.size + ")");
+    }
+    return sb.toString();
+  }
+
   String
   dump_xen (VirtualBlockDevice vbd)
   {
index 6d5877da2d349923487b40367212314681c31379..256cdcc7cb6aadf6539b01ed84ecb7c5019b296e 100755 (executable)
@@ -14,14 +14,14 @@ import java.io.PrintWriter;
 public class
 VirtualDiskManager
 {
-  VirtualDisk free;
+  VirtualDisk free_disk;
   Vector virtual_disks;
   Hashtable virtual_block_devices;
   Hashtable key_hash;
 
   VirtualDiskManager ()
   {
-    free = new VirtualDisk("free");
+    free_disk = new VirtualDisk("free");
 
     virtual_disks = new Vector(10,5);
     flush_virtual_block_devices();
@@ -37,7 +37,7 @@ VirtualDiskManager
   public void
   add_xeno_partition (Partition partition, long size)
   {
-    free.add_new_partition (partition, size);
+    free_disk.add_new_partition (partition, size);
     return;
   }
 
@@ -54,7 +54,7 @@ VirtualDiskManager
     {
       Extent e;
 
-      e = free.remove_extent();
+      e = free_disk.remove_extent();
       if (e == null)
       {
        return null;
@@ -88,7 +88,7 @@ VirtualDiskManager
       e = vd.remove_extent();
       while (e != null)
       {
-       free.add_extent(e);
+       free_disk.add_extent(e);
        e = vd.remove_extent();
       }
     }
@@ -198,7 +198,7 @@ VirtualDiskManager
   public void
   add_free (VirtualDisk vd)
   {
-    free = vd;
+    free_disk = vd;
   }
 
   public String
@@ -218,7 +218,7 @@ VirtualDiskManager
   public String
   dump_free()
   {
-    return(free.dump(true, false));
+    return(free_disk.dump(true, false));
   }
 
   public String
@@ -265,7 +265,7 @@ VirtualDiskManager
   dump_xml(PrintWriter out)
   {
     out.println("<free>");
-    free.dump_xml(out);
+    free_disk.dump_xml(out);
     out.println("</free>");
     out.println("<virtual_disks>");
     for (int i = 0; i < virtual_disks.size(); i++)